package com.zmn.plat.admin.controller.service.item.servicetime;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTime;
import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTimeQuery;
import com.zmn.plat.services.interfaces.service.item.servicetime.ServServiceTimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;


/**
 * 项目服务时长基础查询Controller
 *
 * @author yangshuangping
 * @since 2021/07/27 10:36
 */
@Slf4j
@RestController
@RequestMapping("/time/servicetime")
public class ServServiceTimeListController extends PlatBaseController {

    @Resource
    private ServServiceTimeService servServiceTimeService;

    /**
     * 描述: 查询列表
     *
     * @author yangshuangping
     * @since 2021/07/27 10:36
     */
    @RequestMapping("/list")
    public ModelAndView list(@ModelAttribute ServServiceTimeQuery query) {

        List<ServServiceTime> items = servServiceTimeService.listPageByQuery(query);

        ModelAndView mv = new ModelAndView("time/servservicetime/list");
        mv.addObject("items", items);
        mv.addObject("vo", query);

        return mv;
    }

    /**
     * 描述: 详情
     *
     * @author yangshuangping
     * @since 2021/07/27 10:36
     */
    @RequestMapping("/addEditView")
    public ModelAndView info(@RequestParam(value = "serviceTimeId") Integer serviceTimeId) {

        ServServiceTime servServiceTime;
        if (NumberUtil.isNullOrZero(serviceTimeId)) {
            servServiceTime = new ServServiceTime();
        } else {
            servServiceTime = servServiceTimeService.findById(serviceTimeId);
        }
        ModelAndView mv = new ModelAndView("time/servservicetime/detail");
        mv.addObject("servServiceTime", servServiceTime);

        return mv;
    }

}
